package com.security.it.authentication.common;

import com.security.it.core.enums.ValidateCodeType;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component("validateCodeProcessorHolder")
public class ValidateCodeProcessorHolder {

    @Resource
    private List<AbstractValidateCodeProcessor> validateCodeProcessors;

    public AbstractValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) {
        for (AbstractValidateCodeProcessor processor : validateCodeProcessors) {
            if (processor.accept(type)) {
                return processor;
            }
        }
        throw new RuntimeException("not accept Bean!");
    }
}
